﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ProfanityChecker
{
    public partial class frmChangePassword : Form
    {
        Settings m_settings;
        public frmChangePassword(Settings settings)
        {
            m_settings = settings;
            InitializeComponent();
        }

        private void btnChange_Click(object sender, EventArgs e)
        {
            string old = txbxOldPassword.Text;
            string newp = txbxNewPassword.Text;
            string conf = txbxConfirmPassword.Text;

            if (string.IsNullOrEmpty(old) || string.IsNullOrEmpty(newp) ||
                string.IsNullOrEmpty(conf))
            {
                MessageBox.Show("Not enough information inputted.", "Big Fat Hairy Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (old.Equals(m_settings.Password))
            {
                if (newp.Equals(conf))
                {
                    m_settings.Password = newp;
                }
                else
                {
                    MessageBox.Show("Passwords do not match.", "Big Fat Hairy Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Current password is incorrect.", "Big Fat Hairy Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
